{include file='public/_header' /}

    <!-- Main Container -->
    <div class="main-container container-fluid">
        <!-- Page Container -->
        <div class="page-container">

            <!-- Page Sidebar -->
			{include file='public/_left' /}
            <!-- /Page Sidebar -->
            <!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                        <li>
                            <i class="fa fa-home"></i>&nbsp;文章管理
                        </li>
                        <li>文章列表</li>
                    </ul>
                </div>
                <!-- /Page Breadcrumb -->
                <!-- Page Body -->
                <div class="page-body">
					<a href="{:url('admin/article/artadd')}" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i>&nbsp;添加文章</a>
					<div class="row">
						<div class="col-xs-12">
							<div class="widget">
								<div class="widget-header">
									<span class="widget-caption">文章列表</span>
									<div class="widget-buttons">
										<!-- 分页 -->
										{$articles|raw|replace_str}
									</div>
								</div>
								<div class="widget-body">
									<table class="table table-hover table-bordered">
										<thead>
											<tr>
												<th>ID</th>
												<th>文章标题</th>
												<th>所属栏目</th>
												<th>是否推荐</th>
												<th>操作</th>
											</tr>
										</thead>
										<tbody>
											{volist name="articles" id="article"}
												<tr>
													<td>{$article.id}</td>
													<td>{$article.title}</td>
													<td>{$article.category.catename}</td>
													<td>{eq name="$article.is_top" value="1"} 已推荐 {else/} 未推荐 {/eq}</td>
													<td>
														{eq name="$article.is_top" value="1"}
															<a href="#" class="btn btn-sm btn-darkorange article-top" istop="{$article.is_top}" dataid="{$article.id}">取消推荐</a>
														{else/}
															<a href="#" class="btn btn-sm btn-azure article-top" istop="{$article.is_top}" dataid="{$article.id}">推荐</a>
														{/eq}
														<a href="{:url('admin/article/artedit', ['id' => $article.id])}" class="btn btn-sm btn-warning">编辑</a>
														<a href="#" class="btn btn-sm btn-danger article-delete" dataid="{$article.id}">删除</a>
													</td>
												</tr>
											{/volist}
										</tbody>
									</table>
								</div>
							</div>
						</div>
					</div>
                </div>
                <!-- /Page Body -->
            </div>
            <!-- /Page Content -->

        </div>
        <!-- /Page Container -->
        <!-- Main Container -->

    </div>

	{include file='public/_js' /}

	<script>
		// 文章置顶（推荐）
		$('.article-top').click(function () {
			var id = $(this).attr('dataid');
			var istop = $(this).attr('istop');
			if (istop ==1 ){
				var msg = '确定取消推荐吗？';
			}else {
				var msg = '确定设为推荐吗？';
			}
			layer.confirm(msg,{
				icon: 3,
				title: '提示'
			}, function (index) {
				layer.close(index);
				$.ajax({
					url: "{:url('admin/article/top')}",
					type: 'post',
					dataType: 'json',
					data: {id: id, is_top: istop},
					success: function (data) {
						if (data.code == 1){
							layer.msg('文章已推荐', {
								icon: 6,
								time: 500
							}, function () {
								location.href = data.url;
							});
						}else {
							layer.open({
								title: '推荐设置失败',
								content: data.msg,
								icon: 5,
								anim: 6
							});
						}

					}
				});
			});

			return false;
		});

		// 文章删除
		$('.article-delete').click(function (){
			var id = $(this).attr('dataid');
			layer.confirm('确定删除该文章吗？',{
				icon: 3,
				title: '提示'
			}, function (index) {
				layer.close(index);
				$.ajax({
					url: "{:url('admin/article/artdel')}",
					type: "post",
					dataType: 'json',
					data: {id: id},
					success: function (data) {
						if (data.code == 1){
							layer.msg('文章删除成功', {
								icon: 6,
								time: 500
							}, function () {
								location.href = data.url;
							});
						}else {
							layer.open({
								title: '文章删除失败',
								content: data.msg,
								icon: 5,
								anim: 6
							});
						}
					}
				});
			});

			return false;
		});
	</script>

</body>
<!--  /Body -->
</html>
